#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int longestConsecutive(vector<int>& nums)
    {
        unordered_set<int> arr(nums.begin(), nums.end());
        int ret = 0;
        int len = 0;
        for (auto s : arr)
        {
            if (!arr.count(s - 1))
            {
                int len = 1;
                while (arr.count(++s)) { len++; }
                ret = max(ret, len);
            }
        }
        return ret;
    }
};